﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsAcess
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“dS_Student.SEXENUM”中。您可以根据需要移动或删除它。
            this.sEXENUMTableAdapter.Fill(this.dS_Student.SEXENUM);
            // TODO: 这行代码将数据加载到表“dS_Student.STUDENTINFO”中。您可以根据需要移动或删除它。
            this.sTUDENTINFOTableAdapter.Fill(this.dS_Student.STUDENTINFO);
            // 使用数据源工具时产生的自动代码
            this.sEXDataGridViewTextBoxColumn.DataSource = this.sEXENUMBindingSource;
            this.sEXDataGridViewTextBoxColumn.DisplayMember = "LABELTEXT";
            this.sEXDataGridViewTextBoxColumn.ValueMember = "VALUE";
            this.sEXDataGridViewTextBoxColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
            this.sEXDataGridViewTextBoxColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            // 记得设置这个哟
            dataGridView1.AutoGenerateColumns = false;

            // List 数据源
            List<ComboItem> list = new List<ComboItem>();
            list.Add(new ComboItem("女", 0));
            list.Add(new ComboItem("男", 1));

            // DataTable 数据源
            DataTable dtSex = new DataTable();
            DataColumn columnLABELTEXT = new global::System.Data.DataColumn("LABELTEXT", typeof(string), null, global::System.Data.MappingType.Element);
            dtSex.Columns.Add(columnLABELTEXT);
            DataColumn columnVALUE = new global::System.Data.DataColumn("VALUE", typeof(int), null, global::System.Data.MappingType.Element);
            dtSex.Columns.Add(columnVALUE);
            columnLABELTEXT.MaxLength = 20;
            dtSex.Rows.Add(new object[] { "女", 0 });
            dtSex.Rows.Add(new object[] { "男", 1 });
            // 绑定到 List
            sEXDataGridViewTextBoxColumn.DataSource = list;
            // 绑定到  DataTable
            sEXDataGridViewTextBoxColumn.DataSource = dtSex;

        }
        /// <summary>
        /// 当性别列编辑时使用下拉列表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            try
            {
                if (e.CellStyle != null)
                {

                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
        /// <summary>
        /// 下拉显示项适配
        /// </summary>
        public class ComboItem
        {
            public ComboItem(string text, int value)
            {
                LABELTEXT = text;
                Value = value;
            }
            public string LABELTEXT { get; set; }
            public int Value { get; set; }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                this.sTUDENTINFOTableAdapter.Update(this.dS_Student.STUDENTINFO);
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
    }
}
